<?php
namespace Admin\Controller;
use Admin\Controller\AdminController;
use Think\Page;

class MemberjiluController extends AdminController {
	public function _initialize(){
        parent::_initialize();
    }
	
	 /**
     * 会员列表
     */
    public function index(){
		//批量删除处理
		$id = I('id');
		//dump($id);die;
		if(!empty($id) && is_array($id)){
			$delete['id'] = array('in',$id);
			$re = M('Member')->where($delete)->setField('status',-1);
			if(!$re){
				$this->error('删除失败');
			}
		}
		
		//查询条件处理
		$realname_post = I('realname');
		$nickname_post = I('nickname');
		$type = I('type');
		$post = array('type'=>$type,'realname'=>$realname_post);
		
		
		if(!empty($realname_post)){
			$where['realname'] = array('like',"%{$realname_post}%");
		}
		if(!empty($nickname_post)){
			$where['nickname'] = array('like',"%{$nickname_post}%");
		}
		
		
		//分页处理
		$post_param = $where;
		$post_param['order'] = $order;
		
		$count = M("Member")->where($where)->count();
		$Page  = new \Think\Page($count,20);
		setPageParameter($Page, $post_param);
		$show = $Page->show();
		$list = M('Member')->where($where)->order($order)->limit($Page->firstRow.','.$Page->listRows)->select();
		foreach($list  as $k=>$v){
			$f=M('rob_log');//查询积分助力记录
			$arr['f_open_id']=$v['openid'];
		    $flist=$f->where($arr)->group('open_id')->select();//帮助的所有
		    $num=0;//被助力积分
		    $numprice=0;//被助力金额
		    $cishu=$f->where(array("open_id"=>$v['openid']))->count();//他人助力次数
		    $cishu_ta=$f->where(array("f_open_id"=>$v['openid']))->count();//助力他人次数
			foreach($flist as $kk=>$vv){
	            $re= M('Member')->where(array('openid' =>$vv['open_id']))->find();//所有人的信息
            	$num=$num+$vv['f_score'];
            	$numprice=$numprice+$vv['f_price'];
			}
			$list[$k]['num']=$num;
			$list[$k]['cishu']=$cishu;
			$list[$k]['cishu_ta']=$cishu_ta;
			$list[$k]['numprice']=$numprice;
		}
		
		//赋值给页面上
		$this->assign('post',$post);
		$this->assign('count',$count);
		$this->assign('school_type',$school_type);
		$this->assign('school_name',$school_name);
		$this->assign('grade',$grade);
		$this->assign('class',$class);
		$this->assign('list',$list);
		$this->assign('page',$show);
		$this->display();
		 
    }
    public function jifen_record(){
        $openid=I('userid');
		$f=M('rob_log');//查询积分助力记录
		$flist=$f->where("f_open_id='{$openid}'")->group('open_id')->select();//帮助的所有人
		//dump($re);
		foreach($flist as $k=>$v){
            $re= M('Member')->where(array('openid' =>$v['open_id']))->find();//所有人的信息
            $flist[$k]['userid']=$re['id'];
            $flist[$k]['nickname']=$re['nickname'];
            $flist[$k]['jifen']=$re['jifen'];
            $flist[$k]['heading']=$re['headimg'];
            $flist[$k]['count']=$f->where(array("f_open_id"=>$openid,"open_id"=>$v['open_id']))->count();
            $num=$num+$v['f_score'];
		}
		$flist1=$flist; 
		//$flist1['num']=$num;
		//dump($flist1);
		$this->assign('flist1',$flist1);
		$this->display();

    }
     public function Pinqiang_record(){
        $open_id = I('userid');
        $order = M('rob_orders as o,yang_rob_goods_orders as r')->where("o.order_id = r.order_id and o.open_id='{$open_id}'")->select();
         foreach($order as $k=>$v){
            $time=$v['end_time']-$v['start_time'];
            if($time<=0){
                $order[$k]['time']='已结束';
            }else{
                $order[$k]['time']=date("Y-m-d H:i:s",$time);
            }
        }
        $this->assign('flist1',$order);
        $this->display();
    }
	
}
	
